<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.prime.com.tr/ui">

    <ui:composition template="/template/DefaultTemplate.xhtml">
        <ui:define name="content">
            <h:form >
                <p:panel id="ciabillingrequests" header="Normal Billing Requests" >
                    <p:ajaxStatus style="width:16px;height:16px;">  
                        <f:facet name="start">  
                            <h:graphicImage value="/resources/design/ajaxloading.gif" />  
                        </f:facet>  

                        <f:facet name="complete">  
                            <h:outputText value="" />  
                        </f:facet>  
                    </p:ajaxStatus>  
                    <p:dataTable value="#{billingRequestEntityController.allNormalBillingRequests}" var="item" 
                                 paginator="true" rows="30" rowsPerPageTemplate="30,50,100">
                        <p:column filterBy="#{item.id}" sortBy="#{item.id}">
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListBillingRequestEntityTitle_id}"/>
                            </f:facet>
                            <h:outputText value="#{item.id}"/>
                        </p:column>

                        <p:column filterBy="#{item.salesOrder}" sortBy="#{item.salesOrder}">
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListBillingRequestEntityTitle_salesOrder}"/>
                            </f:facet>
                            <h:outputText value="#{item.salesOrder}"/>
                        </p:column>

                        <p:column filterBy="#{item.salesOrder.customer.fullname}" sortBy="#{item.salesOrder.customer.fullname}">
                            <f:facet name="header">
                                <h:outputText value="Customer"/>
                            </f:facet>
                            <h:outputText value="#{item.salesOrder.customer.fullname}"/>
                        </p:column>

                        <p:column filterBy="#{item.requestedAmount}" sortBy="#{item.requestedAmount}">
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListBillingRequestEntityTitle_requestedAmount}"/>
                            </f:facet>
                            <h:outputText value="#{item.requestedAmount}"/>
                        </p:column>

                        <p:column filterBy="#{item.invoice}" sortBy="#{item.invoice}">
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListBillingRequestEntityTitle_invoice}"/>
                            </f:facet>
                            <h:commandLink value="#{item.invoice.id}" rendered="#{item.hasInvoice()}"
                                           action="/entities/customerInvoiceEntity/View">
                                <f:setPropertyActionListener target="#{customerInvoiceEntityController.current}"
                                                             value="#{item.invoice}" />
                            </h:commandLink>
                            <p:commandLink value="generate invoice" rendered="#{!item.hasInvoice()}"
                                           action="#{billingRequestEntityController.generateInvoice}"
                                           update="@form:displayInvoice" oncomplete="invoiceDialog.show()"
                                           process="@form">
                                <f:setPropertyActionListener value="#{item}"  
                                                             target="#{billingRequestEntityController.current}" /> 
                            </p:commandLink>
                        </p:column>

                        <p:column filterBy="#{item.createdAt.toString()}" sortBy="#{item.createdAt.toString()}">
                            <f:facet name="header">
                                <h:outputText value="#{bundle.ListBillingRequestEntityTitle_createdAt}"/>
                            </f:facet>
                            <h:outputText value="#{item.createdAt.toString()}">
                            </h:outputText>
                        </p:column>
                    </p:dataTable>
                </p:panel>

                <p:dialog header="Generated Invoice" widgetVar="invoiceDialog" closable="false" width="800">  
                    <h:panelGroup id="displayInvoice" >
                        <ui:include src="/entities/customerInvoiceEntity/ViewNormalInvoice.xhtml" />
                    </h:panelGroup>
                    <br />
                    <p:commandButton ajax="false" value="save" action="/entities/customerInvoiceEntity/View.xhtml" />
                    &nbsp;
                    <p:menuButton value="save and post" >
                        <p:menuitem value="email" 
                                    actionListener="#{customerInvoiceEntityController.postInvoiceViaEmail}" 
                                    action="/entities/customerInvoiceEntity/View.xhtml?faces-redirect=true"
                                    onclick="invoiceDialog.hide()"/>
                        <p:menuitem ajax="false" value="print" 
                                    action="#{customerInvoiceEntityController.postInvoice}"
                                    onclick="invoiceDialog.hide()">
                            <p:fileDownload value="#{downloadPdf.download()}"/> 
                        </p:menuitem>
                    </p:menuButton>
                </p:dialog>
            </h:form>
        </ui:define>
    </ui:composition>

</html>
